package com.org.controller;

import com.org.common.PageBean;
import com.org.pojo.Banner;
import com.org.common.Result;
import com.org.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: BannerController
 * Package: com.org.controller
 * Description:
 *
 * @Author Origin
 * @Create 2024/2/24 22:00
 * @Version 1.0
 */
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    @PostMapping("/add")
    public Result add(@RequestBody Banner banner){
        bannerService.add(banner);
        return Result.success();
    }


    @GetMapping("/delete")
    public Result delete(Integer id){
        bannerService.delete(id);
        return Result.success();
    }

    @GetMapping("/detail")
    public Result<Banner> detail(Integer id){
        Banner b = bannerService.detail(id);
        return Result.success(b);
    }

    @PostMapping("/update")
    public Result update(@RequestBody Banner banner){
        bannerService.update(banner);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<Banner>> list(){
        List<Banner> l = bannerService.list();
        return Result.success(l);
    }

    @GetMapping("/allList")
    public Result<PageBean<Banner>> allList(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) String title,    //非必须
            @RequestParam(required = false) String content,   //非必须
            @RequestParam(required = false) String communityId   //非必须

    ){
        PageBean<Banner> pb = bannerService.allList(pageNum, pageSize, title, content, communityId);
        return Result.success(pb);
    }

}
